#include "frmselectpiece.h"
#include "ui_frmselectpiece.h"

extern int countWhoFirst;
extern int countPlayer1Use;
extern bool isFirstStep;
extern int chessBoard[15][15];
extern int gameMode;

FrmSelectPiece::FrmSelectPiece(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FrmSelectPiece)
{
    ui->setupUi(this);
    groupButtonPlayer1Piece=new QButtonGroup(this);
    groupButtonPlayer1Piece->addButton(ui->btnBlack,0);
    groupButtonPlayer1Piece->addButton(ui->btnWhite,1);

    groupButtonWhoFirst=new QButtonGroup(this);
    groupButtonWhoFirst->addButton(ui->btnBlackFirst,0);
    groupButtonWhoFirst->addButton(ui->btnWhiteFirst,1);
}

FrmSelectPiece::~FrmSelectPiece()
{
    delete ui;
}

bool FrmSelectPiece::getWhoFirst()
{
    return whoFirst;
}

bool FrmSelectPiece::getPlayer1Use()
{
    return player1Use;
}

void FrmSelectPiece::on_buttonBox_accepted()
{
    isFirstStep=true;
    int temp=groupButtonWhoFirst->checkedId();
    if(temp==0)
    {
        whoFirst=false;      //黑子
    }
    else
    {
        whoFirst=true;
    }

    temp=groupButtonPlayer1Piece->checkedId();
    if(temp==0)
    {
        player1Use=false;            //黑子
    }
    else
    {
        player1Use=true;
    }


    if(getWhoFirst() == false && getPlayer1Use() == false){
          countWhoFirst = 0;//黑色先手
          countPlayer1Use = 0;//玩家1为黑色
          isFirstStep = true;

    }
    else if(getWhoFirst() == false && getPlayer1Use() == true){
        countWhoFirst = 0;//黑色先手
        countPlayer1Use = 1;//玩家1为白色
        isFirstStep = true;
    }
    else if(getWhoFirst() == true && getPlayer1Use() == false){
        countWhoFirst = 1;//白色先手
        countPlayer1Use = 0;//玩家1为黑色
        isFirstStep = true;
    }
    else if(getWhoFirst() == true && getPlayer1Use() == true){
        countWhoFirst = 1;//白色先手
        countPlayer1Use = 1;//玩家1为白色
        isFirstStep = true;
    }

    restart_emit();

    this->close();
}
